老生常谈了,直接看代码。 bufferedimage.getColorModel().getTransparency()以获得原始图片透明度用于生成缓存图,在缓存图进行相应操作即可。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) /** *//** * 旋转图片为指定角度 * * @param bufferedimage * 目标图像 * @param degree * 旋转角度 * @return */ public static BufferedImage rotateImage(final BufferedImage bufferedimage,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) final int degree) ...{ int w = bufferedimage.getWidth(); int h = bufferedimage.getHeight(); int type = bufferedimage.getColorModel().getTransparency(); BufferedImage img; Graphics2D graphics2d; (graphics2d = (img = new BufferedImage(w, h, type)) .createGraphics()).setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2); graphics2d.drawImage(bufferedimage, 0, 0, null); graphics2d.dispose(); return img; }![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) /** *//** * 变更图像为指定大小 * * @param bufferedimage * 目标图像 * @param w * 宽 * @param h * 高 * @return */ public static BufferedImage resizeImage(final BufferedImage bufferedimage,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) final int w, final int h) ...{ int type = bufferedimage.getColorModel().getTransparency(); BufferedImage img; Graphics2D graphics2d; (graphics2d = (img = createImage(w, h, type)) .createGraphics()).setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2d.drawImage(bufferedimage, 0, 0, w, h, 0, 0, bufferedimage .getWidth(), bufferedimage.getHeight(), null); graphics2d.dispose(); return img; }![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) /** *//** * 水平翻转图像 * * @param bufferedimage 目标图像 * @return */![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) public static BufferedImage flipImage(final BufferedImage bufferedimage) ...{ int w = bufferedimage.getWidth(); int h = bufferedimage.getHeight(); BufferedImage img; Graphics2D graphics2d; (graphics2d = (img = createImage(w, h, bufferedimage .getColorModel().getTransparency())).createGraphics()) .drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null); graphics2d.dispose(); return img; }
|